package cn.iocoder.yudao.module.engine.service.core.engine.impl;

import cn.hutool.core.util.RandomUtil;
import cn.iocoder.yudao.module.engine.service.core.engine.IEngineConfigService;
import cn.iocoder.yudao.module.infra.api.config.IConfigApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

@Service
@Slf4j
public class EngineConfigServiceImpl implements IEngineConfigService {
    private static final String CONFIG_KEY_MIN_PLAYBACK_INTERVAL = "auxiliary_data.min_playback_interval_ms"; // 播放间隔（毫秒），最小
    private static final String CONFIG_KEY_MAX_PLAYBACK_INTERVAL = "auxiliary_data.max_playback_interval_ms"; // 播放间隔（毫秒），最大

    @Resource
    private IConfigApi configApi;


    @Override
    public int getPlaybackIntervalMs() {
        final String min = configApi.getValueByKey(CONFIG_KEY_MIN_PLAYBACK_INTERVAL);
        final Integer minPlaybackIntervalMs = Integer.valueOf(min);

        final String max = configApi.getValueByKey(CONFIG_KEY_MAX_PLAYBACK_INTERVAL);
        final Integer maxPlaybackIntervalMs = Integer.valueOf(max);

        final int value = RandomUtil.randomInt(minPlaybackIntervalMs, maxPlaybackIntervalMs);
        return value;
    }

}
